#!/usr/bin/python

'''
Created on Apr 21, 2011
only for posix
first usable? program in python
@author: jose
'''

import os
import sys
import threading

def main(argv):
	time = 0
	try:
		if argv[1] < 0: sys.exit(1)
		if argv[2] <= 0: time = 1
		else: time = argv[2]
		letsdoit(argv[1],time)
	except IndexError:
		usage()
		sys.exit(2)

def letsdoit(pid,time):
	print "Killing process:", pid, "in", time, "seconds."
	print "kill -9 " + pid
	#really... this way? bash becomes a better option now :S
	def killing():
		os.system("kill -9 " + pid)
	thread = threading.Timer(float(time), killing)
	thread.start()

def usage():
	print """This has to be used in this way:\n
	shutpdown.py PID time_in_seconds\n
	\n
	It will shutdown that PID in n seconds, just for me sleeping :)
	"""

if __name__ == '__main__':
	main(sys.argv)
else:
	print "Don't do this please"
